<template>
	<div>
		<el-breadcrumb separator-class="el-icon-arrow-right">
		  	<el-breadcrumb-item :to="{ path: '/goods' }">首页</el-breadcrumb-item>
		  	<el-breadcrumb-item>导入文件</el-breadcrumb-item>
		</el-breadcrumb>
		
			<el-upload
			  class="upload-demo"
			  ref="upload"
			  action="/excel/goodsImport"
			  :on-preview="handlePreview"
			  :on-remove="handleRemove"
			  :file-list="fileList"
			  :limit="1"
			  :on-exceed="exceed"
			  :beforeUpload="beforeAvatarUpload"
			  :auto-upload="false">
			  <el-button slot="trigger" size="small" type="primary">上传成品文件</el-button>
			  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
			 <!-- <div slot="tip" class="el-upload__tip">只能上传xls文件，且不超过500kb</div>-->
			</el-upload>
			
			
			<el-upload style="margin-top:100px;"
			  class="upload-demo"
			  ref="uploads"
			  action="/excel/stoneImport"
			  :on-preview="handlePreview"
			  :on-remove="handleRemove"
			  :file-list="fileList"
			  :limit="1"
			  :on-exceed="exceed"
			  :beforeUpload="beforeAvatarUpload"
			  :auto-upload="false">
			  <el-button slot="trigger" size="small" type="primary">上传石料文件</el-button>
			  <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUploads">上传到服务器</el-button>
			  <div slot="tip" class="el-upload__tip">只能上传xls文件，且不超过500kb</div>
			</el-upload>
		
	</div>
</template>

<script>
  export default {
    data() {
      return {
        fileList: [],
      };
    },
    methods: {
    
    	beforeAvatarUpload(file) {
				var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)				
				const extension = testmsg === 'xls'
				const isLt2M = file.size / 1024 / 1024 < 10
				if(!extension) {
					this.$message({
						message: '上传文件只能是 xls格式!',
						type: 'warning'
					});
				}
				if(!isLt2M) {
					this.$message({
						message: '上传文件大小不能超过 10MB!',
						type: 'warning'
					});
				}
				return extension  && isLt2M
			},
    
    
      submitUpload() {
        this.$refs.upload.submit();
      },
      
      submitUploads() {
        this.$refs.uploads.submit();
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      exceed() {
        //重复选择文件,弹出错误弹窗
        this.$alert("最多仅支持上传一个文件")
    },
    }
  }
</script>